using JT808Protocol.Common;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace JT808Protocol.Models.BodyParserStrategy
{
    /// <summary>
    /// 终端补传分包请求
    /// </summary>
    public class DrSupplement_0x0005 : IJT808Body
    {
        /// <summary>
        /// 原始消息流水号
        /// </summary>
        [JsonPropertyName("原始消息流水号")] public ushort OriginSn { get; set; }

        /// <summary>
        /// 重装包总数
        /// </summary>
        [JsonPropertyName("重装包总数")] public ushort PackageSum { get; set; }

        /// <summary>
        /// 重传 ID 表
        /// </summary>
        [JsonPropertyName("重传 ID 表")] public List<ushort> Ids { get; set; } = new List<ushort>();

        public override IJT808Body ReadBody(ReadOnlySpan<byte> source, ref int index)
        {
            // 原始消息流水号
            OriginSn = ParseHelper.Uint16(ref source, index);

            // 重传包总数
            index += 2;
            PackageSum = ParseHelper.Uint16(ref source, index);

            // 重传 ID 列表
            for (int i = 0; i < PackageSum; i++)
            {
                index += 2;
                Ids.Add(ParseHelper.Uint16(ref source, index));
            }

            return this;
        }

        public override List<byte> WriteToBytes()
        {
            throw new NotImplementedException();
        }
    }
}